package hibernate;

import java.util.Date;
import java.util.List;
import java.util.Set;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * A data access object (DAO) providing persistence and search support for
 * HouseInfo entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see hibernate.HouseInfo
 * @author MyEclipse Persistence Tools
 */

public class HouseInfoDAO extends HibernateDaoSupport {
	private static final Logger log = LoggerFactory
			.getLogger(HouseInfoDAO.class);
	// property constants
	public static final String DISTRICT = "district";
	public static final String UNIT_PRICE = "unitPrice";
	public static final String FOREGIFT = "foregift";
	public static final String TITLE = "title";
	public static final String ADDRESS = "address";
	public static final String BEDROOM = "bedroom";
	public static final String HALL = "hall";
	public static final String TOILET = "toilet";
	public static final String HOUSE_TYPE = "houseType";
	public static final String JOINT_RENT = "jointRent";
	public static final String MAX_NUMBER = "maxNumber";
	public static final String AREA = "area";
	public static final String HEIGHT = "height";
	public static final String FLOOR = "floor";
	public static final String AGE = "age";
	public static final String HOUSE_STATE = "houseState";
	public static final String RENT_UNIT = "rentUnit";
	public static final String AT_LEAST_RENT = "atLeastRent";
	public static final String AT_LEAST_UNIT = "atLeastUnit";
	public static final String DESCRIPTION = "description";
	public static final String CITY = "city";
	public static final String PROVINCE = "province";
	public static final String VIEW_NUMBER = "viewNumber";
	public static final String VISIT_NUMBER = "visitNumber";

	protected void initDao() {
		// do nothing
	}

	public void save(HouseInfo transientInstance) {
		log.debug("saving HouseInfo instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(HouseInfo persistentInstance) {
		log.debug("deleting HouseInfo instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public HouseInfo findById(java.lang.Integer id) {
		log.debug("getting HouseInfo instance with id: " + id);
		try {
			HouseInfo instance = (HouseInfo) getHibernateTemplate().get(
					"hibernate.HouseInfo", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(HouseInfo instance) {
		log.debug("finding HouseInfo instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding HouseInfo instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from HouseInfo as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByDistrict(Object district) {
		return findByProperty(DISTRICT, district);
	}

	public List findByUnitPrice(Object unitPrice) {
		return findByProperty(UNIT_PRICE, unitPrice);
	}

	public List findByForegift(Object foregift) {
		return findByProperty(FOREGIFT, foregift);
	}

	public List findByTitle(Object title) {
		return findByProperty(TITLE, title);
	}

	public List findByAddress(Object address) {
		return findByProperty(ADDRESS, address);
	}

	public List findByBedroom(Object bedroom) {
		return findByProperty(BEDROOM, bedroom);
	}

	public List findByHall(Object hall) {
		return findByProperty(HALL, hall);
	}

	public List findByToilet(Object toilet) {
		return findByProperty(TOILET, toilet);
	}

	public List findByHouseType(Object houseType) {
		return findByProperty(HOUSE_TYPE, houseType);
	}

	public List findByJointRent(Object jointRent) {
		return findByProperty(JOINT_RENT, jointRent);
	}

	public List findByMaxNumber(Object maxNumber) {
		return findByProperty(MAX_NUMBER, maxNumber);
	}

	public List findByArea(Object area) {
		return findByProperty(AREA, area);
	}

	public List findByHeight(Object height) {
		return findByProperty(HEIGHT, height);
	}

	public List findByFloor(Object floor) {
		return findByProperty(FLOOR, floor);
	}

	public List findByAge(Object age) {
		return findByProperty(AGE, age);
	}

	public List findByHouseState(Object houseState) {
		return findByProperty(HOUSE_STATE, houseState);
	}

	public List findByRentUnit(Object rentUnit) {
		return findByProperty(RENT_UNIT, rentUnit);
	}

	public List findByAtLeastRent(Object atLeastRent) {
		return findByProperty(AT_LEAST_RENT, atLeastRent);
	}

	public List findByAtLeastUnit(Object atLeastUnit) {
		return findByProperty(AT_LEAST_UNIT, atLeastUnit);
	}

	public List findByDescription(Object description) {
		return findByProperty(DESCRIPTION, description);
	}

	public List findByCity(Object city) {
		return findByProperty(CITY, city);
	}

	public List findByProvince(Object province) {
		return findByProperty(PROVINCE, province);
	}

	public List findByViewNumber(Object viewNumber) {
		return findByProperty(VIEW_NUMBER, viewNumber);
	}

	public List findByVisitNumber(Object visitNumber) {
		return findByProperty(VISIT_NUMBER, visitNumber);
	}

	public List findAll() {
		log.debug("finding all HouseInfo instances");
		try {
			String queryString = "from HouseInfo";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public HouseInfo merge(HouseInfo detachedInstance) {
		log.debug("merging HouseInfo instance");
		try {
			HouseInfo result = (HouseInfo) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(HouseInfo instance) {
		log.debug("attaching dirty HouseInfo instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(HouseInfo instance) {
		log.debug("attaching clean HouseInfo instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static HouseInfoDAO getFromApplicationContext(ApplicationContext ctx) {
		return (HouseInfoDAO) ctx.getBean("HouseInfoDAO");
	}
}